package org.smartboot.flow.core.builder;


import org.smartboot.flow.core.attribute.Attributes;
import org.smartboot.flow.core.component.Component;
import org.smartboot.flow.core.executable.Executable;
import org.smartboot.flow.core.executable.ExecutableAdapter;
import org.smartboot.flow.core.util.AssertUtil;

/**
 * @author qinluo
 * @date 2022-11-11 21:49:01
 * @since 1.0.0
 */
public class ExecutableBuilder<T, S> extends AbstractComponentBuilder<T, S> {

    public Component<T, S> newAdapter(Executable<T, S> executable) {
        AssertUtil.notNull(executable, "must not be null");
        ExecutableAdapter<T, S> adapter = new ExecutableAdapter<>(executable);
        super.applyValues(adapter);
        return adapter;
    }

    /**
     * Created as pure component.
     */
    public Component<T, S> asComponent(Executable<T, S> executable) {
        AssertUtil.notNull(executable, "must not be null");
        return new ExecutableAdapter<>(executable);
    }

    public ExecutableBuilder<T, S> apply(Attributes attributes, Object value) {
        super.apply(attributes, value);
        return this;
    }

    public static <T, S> ExecutableBuilder<T, S> newBuilder() {
        return new ExecutableBuilder<>();
    }
}
